package com.hly.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hly.common.utils.PageUtils;
import com.hly.common.utils.Query;
import com.hly.product.dao.SkuInfoDao;
import com.hly.product.entity.SkuInfoEntity;
import com.hly.product.service.SkuInfoService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("skuInfoService")
public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoDao, SkuInfoEntity> implements SkuInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SkuInfoEntity> page = this.page(
                new Query<SkuInfoEntity>().getPage(params),
                new QueryWrapper<SkuInfoEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 根据id 查询一个
     * @param skuId
     * @return
     */
    @Override
    public SkuInfoEntity getBySkuId(Long skuId) {
        return baseMapper.selectById(skuId);
    }

    /**
     * 根据商品 spuId , 查询所有 SkuInfoEntity
     * @param spuId
     * @return
     */
    @Override
    public List<SkuInfoEntity> selectListBySpuId(Long spuId) {
        return this.list(new QueryWrapper<SkuInfoEntity>().eq("spu_id",spuId));
    }

}